<?php
//  This file is part of EkkinCMS.
//
//  EkkinCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  EkkinCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with EkkinCMS.  If not, see <http://www.gnu.org/licenses/>.

$menu_data = menu_get_item($current_page, $lang);
$menu_entry = $menu_data[0];
$menu_parent = $menu_data[1];
$menu_translated = $menu_data[3];
$menu_rank = $menu_data[2];

echo $menu_translated;

if ($menu_translated == 0){
    $db->exec( "INSERT INTO menu (position, title, id, lang, hidden) VALUES ($menu_rank, \"\", $current_page, \"$lang\", 0) ");
}

$r = $db->get_values_c( "pages", "id = $current_page AND lang = \"$lang\"" );
$en = 0;
if (!$r[id]) {
    $db->exec( "INSERT INTO pages (id, title, content, lang) VALUES ($current_page, \"\", \"\", \"$lang\") ");
    $r = $db->get_values_c( "pages", "id = $current_page AND (lang = \"en\" OR lang = \"en_US\") " );
    $en = 1;
}

if (empty($r[content])){
    $en = 1;
    $r = $db->get_values_c( "pages", "id = $current_page AND (lang = \"en\" OR lang = \"en_US\") " );
}

if ($main_site_gtrans == 'true' and $en == 1 ){
    $r[title] = htmlentities(util_translate(html_entity_decode($r[title]), "en", $lang), ENT_QUOTES);

    $r[content] = util_translate(html_entity_decode($r[content]), "en", $lang);
    $menu_entry = util_translate($menu_entry, "en", $lang);
}


$site_title = _("Translate")." ("._("to lang").") - ".html_entity_decode($r[title]);

echo $site_dir;
include("admin/edit-tinymce.php");
//$site_head_extra = "<script type=\"text/javascript\" src=\"ext_lib/ckeditor/ckeditor_basic.js\"></script>


$site_content = $editor.'
        <form method="post">
            <table class="admin-edit-page">
                <tr>
                    <td width="30%"> '._("Title").': </td>
                    <td width="40%"> <input name="tr-title" type="text" size="40%" value="'.html_entity_decode($r[title]).'"> </td>
                    <td width="30%"></td>
                </tr>
                <tr>
                    <td>'._("Menu entry").':</td>
                    <td><input name="tr-menu-title" type="text" size="40%" value="'.$menu_entry.'"> </td>
                    <td><div class="admin-comment">('._("Leave empty for none").')</div></td>
                </tr>
            </table>
            <p></p>
            <p></p>
            <p></p>
            <p>
                '._("Site content").':<br />
                <textarea name="tr-content">'.$r[content].'</textarea>';

$site_content .= '<script type="text/javascript">
    CKEDITOR.replace( "tr-content" );
</script>';

$site_content .= '
            </p>
            <p>
                <input type="hidden" name="tr-id" value="'.$current_page.'"/>
                <input type="hidden" name="tr-lang" value="'.$lang.'"/>
                <input type="submit" name="submit-tr" value="'."Submit".'"/>
            </p>
        </form>';
?>
